<template>
    <div class="flex flex-col flex-1 p-2">
        <div class="flex justify-between">
            <div class="flex-1"></div>
            <div>
                <!-- <el-button type="primary" @click="openDialog">新增</el-button> -->
            </div>
        </div>
        <CustomTable
            class="mt-2"
            :data="tableData"
            :total="tableTotal"
            v-model:page-size="pageSize"
            @pageSize="getList"
            v-model:currentPage="pageNum"
            @currentPage="getList"
        >
            <el-table-column type="index" width="60" label="序号" />
            <el-table-column prop="storeId" label="店铺" />
            <el-table-column prop="categoryId" label="商品分类" />
            <el-table-column prop="goodsName" label="商品名称" />
            <el-table-column prop="goodsImg" label="图片" />
            <el-table-column prop="goodsPrice" label="价格" />
            <el-table-column prop="goodsSpec" label="规格" />
        </CustomTable>
    </div>
    <CustomDialog v-model:show="addDialog" title="新增商品" width="600px" @cancel="cancelDialog" @confirm="submitForm">
        <el-form ref="formRef" :model="goodsForm" label-width="auto">
            <el-form-item label="商品名称" prop="goodsName">
                <el-input v-model="goodsForm.goodsName"></el-input>
            </el-form-item>
            <el-form-item label="商品图片" prop="goodsImg">
                <SingleUpload v-model="goodsForm.goodsImg"></SingleUpload>
            </el-form-item>
            <el-form-item label="商品价格" prop="goodsPrice"
                ><el-input v-model="goodsForm.goodsPrice"></el-input
            ></el-form-item>
            <el-form-item label="商品规格" prop="goodsSpec"
                ><el-input v-model="goodsForm.goodsSpec"></el-input
            ></el-form-item>
        </el-form>
        {{ goodsForm }}
    </CustomDialog>
</template>

<script setup lang="ts">
import CustomTable from '@/components/CustomTable.vue'
import { onMounted, reactive, ref } from 'vue'
import { getFarmOrderList } from '@/apis/order'
import CustomDialog from '@/components/CustomDialog.vue'
import SingleUpload from '@/components/SingleUpload.vue'
const tableData = ref([])
const tableTotal = ref(0)
const pageSize = ref(10)
const pageNum = ref(1)

const getList = async () => {
    const res = await getFarmOrderList({
        pageNum: pageNum.value,
        pageSize: pageSize.value
    })
    console.log(res)
    tableData.value = res.list
    tableTotal.value = res.total
}
const addDialog = ref()
const openDialog = () => {
    addDialog.value = true
}
const cancelDialog = () => {
    addDialog.value = false
}
const submitForm = () => {
    addDialog.value = false
}

const goodsForm = reactive({
    goodsName: '',
    goodsImg: '',
    goodsPrice: '',
    goodsSpec: ''
})
onMounted(() => {
    getList()
})
</script>

<style scoped></style>
